package com.sinosoft.hydra.um.commons;

import org.apache.commons.lang.StringUtils;

import java.util.*;

/**
 * Created by Administrator on 2016/3/31.
 */
public class ProgressParams {

    private Map<String, String> params;
    private String queryParam;
    private List<String> args;
    private String choice;
    private Set<String> userIds;
    private Set<String> orgIds;
    private int rollback = 0;
    private boolean each = false;

    public boolean isEach() {
        return each;
    }

    public int getRollback() {
        return rollback;
    }

    public String getQueryParam() {
        return queryParam;
    }

    public ProgressParams setQueryParam(String queryParam) {
        this.queryParam = queryParam;
        return this;
    }

    public Set<String> getUserIds() {
        return userIds;
    }

    public Set<String> getOrgIds() {
        return orgIds;
    }


    public ProgressParams() {
        this.params = new HashMap<String, String>();
        this.args = new ArrayList<String>();
        this.choice = null;
        this.orgIds = new HashSet<String>();
        this.userIds = new HashSet<String>();
    }

    public ProgressParams setUserIds(Set<String> userIds) {
        this.userIds = userIds;
        this.each = false;
        return this;
    }

    public ProgressParams setUserIds(Set<String> userIds, boolean each) {
        this.userIds = userIds;
        this.each = each;
        return this;
    }

    public ProgressParams setChoice(String choice) {
        this.choice = choice;
        return this;
    }

    public ProgressParams rollback() {
        this.rollback++;
        return this;
    }

    public ProgressParams putParam(String key, String value) {
        this.params.put(key, value);
        return this;
    }

    public ProgressParams addArg(String arg) {
        this.args.add(arg);
        return this;
    }

    public String getParamMeters() {
        if (params == null || params.isEmpty()) {
            return "";
        }
        List<String> results = new ArrayList<String>();
        for (Map.Entry<String, String> p : params.entrySet()) {
            results.add(p.getKey() + "=" + p.getValue());
        }
        return StringUtils.join(results, "&");
    }

    public List<String> getArgs() {
        return args;
    }

    public String getChoice() {
        return choice;
    }
}
